package com.weipai.demo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.weipai.demo.enums.RetCode;
import com.weipai.demo.mapper.CreditSettingMapper;
import com.weipai.demo.mapper.DLoansManagerMapper;
import com.weipai.demo.mapper.PayOrderMapper;
import com.weipai.demo.mapper.UserMapper;
import com.weipai.demo.mapper.base.DUserMapper;
import com.weipai.demo.mapper.base.LoansManagerMapper;
import com.weipai.demo.mapper.manager.DCManagerProductMapper;
import com.weipai.demo.mapper.manager.DManagerProductMapper;
import com.weipai.demo.mapper.manager.ManagerProductMapper;
import com.weipai.demo.mapper.search.KeyWordMapper;
import com.weipai.demo.model.CreditSetting;
import com.weipai.demo.model.LoansManager;
import com.weipai.demo.model.ManagerProduct;
import com.weipai.demo.model.PayOrder;
import com.weipai.demo.service.LoansManagerService;
import com.weipai.demo.service.UserService;
import com.weipai.demo.util.LayuiTablePagingResult;
import com.weipai.demo.util.MD5Utils;
import com.weipai.demo.util.PayToolUtil;
import com.weipai.demo.util.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author: 赵项阳
 * @Date: 2019/6/22 11:53
 * @Version 1.0
 */
@Service
public class LoansManagerServiceImpl implements LoansManagerService {

    private static final Logger log = LoggerFactory.getLogger(LoansManagerServiceImpl.class);

    @Autowired
    private LoansManagerMapper LoansManagerMapper;

    @Autowired
    private DLoansManagerMapper dLoansManagerMapper;
    @Autowired
    private KeyWordMapper keyWordMapper;
    @Autowired
    private ManagerProductMapper managerProductMapper;
    @Autowired
    private DManagerProductMapper dManagerProductMapper;
    @Autowired
    private CreditSettingMapper creditSettingMapper;
    @Autowired
    private UserService userService;
    @Autowired
    private DCManagerProductMapper dcManagerProductMapper;
    @Autowired
    private PayOrderMapper payOrderMapper;
    @Autowired
    private DUserMapper dUserMapper;
    @Autowired
    private UserMapper userMapper;

    //信贷经理注册信息
    @Override
    public Response register(LoansManager loansManager) {
        Response response = new Response();

        try {
            LoansManager loansManager1 = new LoansManager();
            loansManager1.setApplyforName(loansManager.getApplyforName());
            Example example = new Example(LoansManager.class);
            example.createCriteria().andEqualTo("applyforMobile", loansManager.getApplyforMobile());
//            List<LoansManager> list = LoansManagerMapper.select(loansManager1);
            List<LoansManager> list = LoansManagerMapper.selectByExample(example);
            if (list.size() != 0) {
                response.setCode(RetCode.REPETITION);
                return response;
            } else {
                loansManager.setIsPay("0");
                loansManager.setStatus(0);
                Date date = new Date();
                loansManager.setCreateTime(date);
                loansManager.setApplyforPassword( MD5Utils.encrypt(loansManager.getApplyforMobile(), loansManager.getApplyforPassword()));
                int insert = LoansManagerMapper.insert(loansManager);

                PayOrder payOrder = new PayOrder();
                payOrder.setApplyName(loansManager.getApplyforName());
                payOrder.setMobile(loansManager.getApplyforMobile());
                payOrder.setStatus(1);
                payOrder.setCreateTime(new Date());
                payOrder.setOrderSn(PayToolUtil.getOutTradeNo());

                CreditSetting creditSetting = new CreditSetting();
                creditSetting.setId(1);
                CreditSetting res = creditSettingMapper.selectByPrimaryKey(creditSetting);
                payOrder.setPayMoney(new BigDecimal(res.getValue()));
                Integer res1 = payOrderMapper.insert(payOrder);


                response.setCode(RetCode.PUSHSUCCESS);

            }
        } catch (Exception e) {
            e.printStackTrace();
            response.setCode(RetCode.REQUEST_ERROR);
            response.setData(e.getMessage());
            log.error("register" + e.getMessage());
        }
        return response;
    }

    //分页展示信贷经理信息
    @Override
    public LayuiTablePagingResult managerShow(Integer page, Integer size, Integer status) {
        LayuiTablePagingResult result = null;
        try {
            PageHelper.startPage(page, size);

            LoansManager loansManager = new LoansManager();
            loansManager.setStatus(status);
//            List<LoansManager> select = LoansManagerMapper.select(loansManager);
            List<LoansManager> select = dLoansManagerMapper.select(loansManager);


            PageInfo<LoansManager> pageInfo = new PageInfo<>(select);
            result = new LayuiTablePagingResult();
            result.setCode(RetCode.SUCCESS.getCode());
            result.setMsg(RetCode.SUCCESS.getMsg());
            result.setCount(pageInfo.getTotal());
            result.setData(pageInfo.getList());
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(RetCode.REQUEST_ERROR);
            result.setData(e.getMessage());
            log.error("managerShow" + e.getMessage());
        }
        return result;
    }

    //审核通过和驳回或删除
    @Override
    public Response isStatus(Integer id, Integer status) {
        Response response = new Response();

        LoansManager loansManager = new LoansManager();
        loansManager.setStatus(status);
        loansManager.setId(id);

        //通过时注册用户
//        if (status != null && status == 1) {
//            LoansManager user = dLoansManagerMapper.selectById(id);
//            String userName = "", password = "", pictureUrl = "", nickName = "",payStatus="";
//            for (int i = 0; i <list.size(); i++) {
//                //取出每一条数据
//                LoansManager user=list.get(i);
            //取出该条记录中的属性
//            userName = user.getApplyforMobile();
//            password = user.getApplyforPassword();
//            pictureUrl = user.getManagerPictureUrl();
//            nickName = user.getApplyforName();
//            payStatus = user.getIsPay();
//            }
//            Integer type = 1;
//
//            int count = userMapper.getUserByUserName(user.getApplyforMobile());
//            if (count > 0) {
////                logger.info("添加用户失败:{}", "登录名不能重复");
//                response.setCode(RetCode.D_RESULT_FAIL_NAMEVAR);
//                response.setMsg("登录名不能重复");
//                return response;
//            }
//            try {
//                DUser dUser = new DUser();
//                dUser.setUserName(user.getApplyforMobile());
//                String password = MD5Utils.encrypt(user.getApplyforMobile(), user.getApplyforPassword());
//                dUser.setUserPassword(password);
//                dUser.setType(type);
//                dUser.setPictureUrl(user.getManagerPictureUrl());
//                dUser.setNickName(user.getApplyforName());
//                dUser.setStatus(Integer.valueOf(user.getIsPay()));
//                dUserMapper.insertSelective(dUser);
//            } catch (Exception e) {
//                response.setMsg(e.getMessage());
//                response.setCode(RetCode.REQUEST_ERROR);
//                return response;
//            }
//        }
        //如果status为空,,删除
        if (status == null && id != null) {
            int delete = LoansManagerMapper.delete(loansManager);
            response.setCode(RetCode.SUCCESS);
        } else {
            if (status != null && id != null) {
                dLoansManagerMapper.updateByStatus(status, id);
                response.setCode(RetCode.UPDATESUCCESS);
            } else {
                response.setCode(RetCode.STATUS_NULL);
                return response;
            }
        }
        return response;
    }

    //修改为已付款  修改订单状态
    @Override
    public Response changePay(Integer id) {
        Response response = new Response();
        try {
            LoansManager loansManager = new LoansManager();
            loansManager.setIsPay("1");
            loansManager.setId(id);
            Integer res = LoansManagerMapper.updateByPrimaryKeySelective(loansManager);
            //如果已經注冊過用戶，把用戶狀態改爲已支付
            LoansManager loansManager1 = dLoansManagerMapper.selectById(id);
//            DUser dUser= new DUser();
//            dUser.setUserName(loansManager1.getApplyforMobile());
//            dUser.setNickName(loansManager1.getApplyforName());
//            DUser user = dUserMapper.selectOne(dUser);
//            if(user != null){
//                DUser dUser1= new DUser();
//                dUser1.setStatus(1);
//                dUser1.setId(user.getId());
//
//                dUserMapper.updateByPrimaryKeySelective(dUser1);
//            }
            Example example = new Example(PayOrder.class);
            example.createCriteria().andEqualTo("mobile", loansManager1.getApplyforMobile());
            PayOrder payOrder = new PayOrder();
            payOrder.setStatus(2);
            payOrder.setPayTime(new Date());
            payOrderMapper.updateByExampleSelective(payOrder, example);
            response.setCode(RetCode.SUCCESS);
            response.setMsg("修改成功");
        } catch (Exception e) {
            response.setCode(RetCode.REQUEST_ERROR);
            response.setMsg(e.getMessage());
        }

//        String userName = "", password = "", pictureUrl = "", nickName = "";
////            for (int i = 0; i <list.size(); i++) {
////                //取出每一条数据
////                LoansManager user=list.get(i);
//        //取出该条记录中的属性
//        userName = user.getApplyforMobile();
//        password = user.getApplyforPassword();
//        pictureUrl = user.getManagerPictureUrl();
//        nickName = user.getApplyforName();
////            }
//        Integer type = 1;
//        userService.saveUser(userName, password, type, pictureUrl, nickName);
//
//        int delete = LoansManagerMapper.delete(loansManager);
//        response.setCode(RetCode.SUCCESS);
//    } else
//
//    {
//        if (status != null && id != null) {
//            dLoansManagerMapper.updateByStatus(status, id);
//            response.setCode(RetCode.UPDATESUCCESS);
//        } else {
//            response.setCode(RetCode.STATUS_NULL);
//            return response;
//        }
//    }
        return response;
    }

    //展示
    @Override
    public Response showKey(Integer status) {
        Response response = new Response();
        try {
            List<String> list = keyWordMapper.selectByStatus(status);
            response.put("list", list);
            response.setCode(RetCode.SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("showKey" + e.getMessage());
        }
        return response;
    }

    //==================================================================================================================

    //页面展示信贷经理信息
    @Override
    public Response show(String phone) {
        Response response = new Response();
        try {
            Map<String, Object> list = dLoansManagerMapper.searchByPhone(phone);
            StringBuilder sb = new StringBuilder((String) list.get("identityCard"));
            sb.replace(6, 14, "********");
            list.put("identityCard",sb.toString());
            response.setData(list);
            response.setCode(RetCode.SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            response.setCode(RetCode.REQUEST_ERROR);
            return response;
        }
        return response;
    }


    //保存信贷经理头像
    @Override
    public Response savePicture(LoansManager loansManager) {
        Response response = new Response();
        if (loansManager.getId() == null) {
            LoansManagerMapper.insert(loansManager);
            response.setCode(RetCode.SUCCESS);

        } else {
            // int i1 = pictureShowMapper.updateByPrimaryKey(pictureShow);
            int i = LoansManagerMapper.updateByPrimaryKeySelective(loansManager);
            if (i > 0) {
                response.setCode(RetCode.UPDATESUCCESS);
            } else {
                response.setCode(RetCode.UPDATEERROR);
                return response;
            }
        }
        return response;
    }


    //页面信贷经理创建贷款产品
    @Override
    public Response saveProduct(ManagerProduct managerProduct) {
        Response response = new Response();
        if (managerProduct.getStatus() == null) {
            managerProduct.setStatus("0");
        }
        if (managerProduct.getPublishStatus() == null) {
            managerProduct.setPublishStatus(0);
        }

        Date date = new Date();
        managerProduct.setCreateTime(date);
        Map<String, Object> list = dLoansManagerMapper.searchByPhone(managerProduct.getManagerPhone());
//        managerProduct.setRegionId((String) list.get("region"));
        managerProduct.setInstitutionalTypeId((Integer) list.get("mechanismId"));
        if (managerProduct.getId() == null) {
            //产品名称相同的不能重复添加
            Integer integer = dManagerProductMapper.selectByName(managerProduct.getProductName());
            if (integer > 0) {
                response.setCode(RetCode.IDENTICAL);
                return response;
            }
            int insert = managerProductMapper.insert(managerProduct);
            if (insert > 0) {
                response.setCode(RetCode.SUCCESS);
            } else {
                response.setCode(RetCode.REQUEST_ERROR);
                return response;
            }
        } else {
            managerProduct.setStatus("0");
            int i = managerProductMapper.updateByPrimaryKeySelective(managerProduct);
            if (i > 0) {
                response.setCode(RetCode.UPDATESUCCESS);
            } else {
                response.setCode(RetCode.REQUEST_ERROR);
                return response;
            }
            return response;
        }
        return response;
    }

    //信贷经理产品展示
    @Override
    public LayuiTablePagingResult showPage(Integer page, Integer size, String status, String managerPhone) {
        LayuiTablePagingResult result = null;

        try {
            PageHelper.startPage(page, size);

            //如果status为空展示全部
            if (status != null) {
                List<Map<String, Object>> products = dManagerProductMapper.selectBystatus(status, managerPhone);

                //将其他要求的id查出并添加到products集合中
                String list = dLoansManagerMapper.selectByPhone(status, managerPhone);
                String[] split = list.split(",");
                List<String> attrList = Arrays.asList(split);
                List<Map<String, Object>> mapList = dManagerProductMapper.selectByAttr(attrList);
                StringBuffer sbf = new StringBuffer();

                for (int i = 0; i < mapList.size(); i++) {
                    Map<String, Object> map = mapList.get(i);
                    String attribute = (String) map.get("attribute");
                    sbf.append(attribute);
                    sbf.append(",");
                }

                for (int i = 0; i < products.size(); i++) {
                    Map<String, Object> map = products.get(i);
                    map.put("attribute1", sbf.toString());
                }

                //将可申请人的id查出并添加到products的集合中
                String licant = dLoansManagerMapper.selectByLicant(status, managerPhone);
                String[] strings = licant.split(",");
                List<String> asList = Arrays.asList(strings);
                List<Map<String, Object>> maps = dManagerProductMapper.selectByAslist(asList);
                StringBuffer sf = new StringBuffer();

                for (int i = 0; i < maps.size(); i++) {
                    Map<String, Object> map = maps.get(i);
                    String attribute = (String) map.get("attribute");
                    sf.append(attribute);
                    sf.append(",");
                }

                for (int j = 0; j < products.size(); j++) {
                    Map<String, Object> map = products.get(j);
                    map.put("attribute", sf.toString());
                }

                PageInfo<ManagerProduct> pageInfo = new PageInfo(products);
                result = new LayuiTablePagingResult();
                result.setCode(RetCode.SUCCESS.getCode());
                result.setMsg(RetCode.SUCCESS.getMsg());
                result.setCount(pageInfo.getTotal());
                result.setData(pageInfo.getList());
            } else {
                List<Map<String, Object>> products = dManagerProductMapper.selectAll(managerPhone);
                PageInfo<ManagerProduct> pageInfo = new PageInfo(products);
                result = new LayuiTablePagingResult();
                result.setCode(RetCode.SUCCESS.getCode());
                result.setMsg(RetCode.SUCCESS.getMsg());
                result.setCount(pageInfo.getTotal());
                result.setData(pageInfo.getList());
            }
        } catch (Exception e) {
            e.printStackTrace();
            result.setData(e.getMessage());
            result.setCode(RetCode.REQUEST_ERROR);
            log.error(e.getMessage());
        }
        return result;
    }


    //信贷经理查看详情
    @Override
    public Response particulars(Integer id) {
        Response response = new Response();
        List<ManagerProduct> managerProducts = dManagerProductMapper.selectById(id);
        response.put("managerProducts", managerProducts);
        response.setCode(RetCode.SUCCESS);
        return response;
    }


    //上下架
    @Override
    public Response upOrDown(Integer id, String status) {
        Response response = new Response();
        try {
            int i = dManagerProductMapper.updateStatus(id, status);
            if (i > 0) {
                response.setCode(RetCode.UPDATESUCCESS);
                return response;
            } else {
                response.setCode(RetCode.REQUEST_ERROR);
                return response;
            }
        } catch (Exception e) {
            response.setCode(RetCode.REQUEST_ERROR);
            response.setData(e.getMessage());
            e.printStackTrace();
            log.error("upOrDown" + e.getMessage());
        }
        return response;
    }

    //信贷经理产品根据id删除
    @Override
    public Response deleteProduct(Integer id) {
        Response response = new Response();
        try {
            int i = dManagerProductMapper.deleteById(id);
            if (i > 0) {
                response.setCode(RetCode.SUCCESS);
            } else {
                response.setCode(RetCode.REQUEST_ERROR);
                return response;
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("deleteProduct" + e.getMessage());
        }
        return response;
    }

    //页面信贷经理信息修改
    @Override
    public Response change(LoansManager loansManager) {
        Response response = new Response();
        try {
            // int i = LoansManagerMapper.updateByPrimaryKey(loansManager);
            int i = dLoansManagerMapper.updateByPrimaryKey(loansManager);
            if (i > 0) {
                response.setCode(RetCode.SUCCESS);
            } else {
                response.setCode(RetCode.REQUEST_ERROR);
                return response;
            }
        } catch (Exception e) {
            response.setCode(RetCode.REQUEST_ERROR);
            response.setData(e.getMessage());
            e.printStackTrace();
            log.error("change" + e.getMessage());
        }
        return response;
    }

    //推荐的热门贷款
    @Override
    public Response recommendList(Integer page, Integer size) {
        Response response = new Response();
        try {
            List<Map<String, Object>> res = dManagerProductMapper.getRecommentList(page, size);
            response.setCode(RetCode.SUCCESS);
            response.setData(res);

        } catch (Exception e) {
            response.setCode(RetCode.REQUEST_ERROR);
            response.setData(e.getMessage());
            e.printStackTrace();
            log.error("change" + e.getMessage());
        }
        return response;
    }


    //==================================================================================================================


    //前端页面分页搜索贷款
    @Override
    public LayuiTablePagingResult search(Integer page, Integer size, ManagerProduct managerProduct) {
        LayuiTablePagingResult result = null;

        try {
            PageHelper.startPage(page, size);

            List<Map<String, Object>> products = dcManagerProductMapper.selectByNull(managerProduct);

            for (Map<String, Object> item : products
            ) {
                if (item.get("other_requirements_id") != null && item.get("other_requirements_id") != "") {
                    String[] split = item.get("other_requirements_id").toString().split(",");
                    List<String> attrList = Arrays.asList(split);
                    List<Map<String, Object>> mapList = dManagerProductMapper.selectByAttr(attrList);
                    StringBuffer sbf = new StringBuffer();
                    for (int i = 0; i < mapList.size(); i++) {
                        Map<String, Object> map = mapList.get(i);
                        String attribute = (String) map.get("attribute");
                        sbf.append(attribute);
                        if (i < mapList.size() - 1) {
                            sbf.append(",");
                        }
                    }
                    item.put("attribute1", sbf.toString());
                }
            }

            //将其他要求的id查出并添加到products集合中
//            String list = dLoansManagerMapper.selectOnlyStatus("1");
//            String[] split = list.split(",");
//            List<String> attrList = Arrays.asList(split);
//            List<Map<String, Object>> mapList = dManagerProductMapper.selectByAttr(attrList);
//            StringBuffer sbf = new StringBuffer();
//
//            for (int i = 0; i < mapList.size(); i++) {
//                Map<String, Object> map = mapList.get(i);
//                String attribute = (String) map.get("attribute");
//                sbf.append(attribute);
//                if(i<mapList.size()-1){
//                    sbf.append(",");
//                }
//            }
//
//            for (int i = 0; i < products.size(); i++) {
//                Map<String, Object> map = products.get(i);
//                map.put("attribute1", sbf.toString());
//            }

            //将可申请人的id查出并添加到products的集合中
//            String licant = dLoansManagerMapper.selectByApp("1");
//            String[] strings = licant.split(",");
//            List<String> asList = Arrays.asList(strings);
//            List<Map<String, Object>> maps = dManagerProductMapper.selectByAslist(asList);
//            StringBuffer sf = new StringBuffer();
//
//            for (int i = 0; i < maps.size(); i++) {
//                Map<String, Object> map = maps.get(i);
//                String attribute = (String) map.get("attribute");
//                sf.append(attribute);
//                if(i<maps.size()-1){
//                    sf.append(",");
//                }
//
//            }
//
//            for (int j = 0; j < products.size(); j++) {
//                Map<String, Object> map = products.get(j);
//                map.put("attribute", sf.toString());
//            }

            PageInfo<ManagerProduct> pageInfo = new PageInfo(products);
            result = new LayuiTablePagingResult();
            result.setCode(RetCode.SUCCESS.getCode());
            result.setMsg(RetCode.SUCCESS.getMsg());
            result.setCount(pageInfo.getTotal());
            result.setData(pageInfo.getList());
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("search" + e.getMessage());
        }
        return result;
    }

    //==================================================================================================================

    //信贷经理页面搜索贷款
    @Override
    public LayuiTablePagingResult managerSearch(Integer page, Integer size, String productName, String status, String createTime, String createTimes, Integer publishStatus, String managerPhone) {
        LayuiTablePagingResult result = null;


        try {
            PageHelper.startPage(page, size);
            //动态查询
            if (createTime == "" && createTimes == "") {
                List<Map<String, Object>> mProduct = dcManagerProductMapper.selectByMProduct(productName, status, publishStatus, managerPhone);
                PageInfo<ManagerProduct> pageInfo = new PageInfo(mProduct);
                result = new LayuiTablePagingResult();
                result.setCode(RetCode.SUCCESS.getCode());
                result.setMsg(RetCode.SUCCESS.getMsg());
                result.setCount(pageInfo.getTotal());
                result.setData(pageInfo.getList());
            } else {
                List<Map<String, Object>> mProduct = dcManagerProductMapper.selectByMAProduct(productName, status, publishStatus, createTime, createTimes, managerPhone);
                PageInfo<ManagerProduct> pageInfo = new PageInfo(mProduct);
                result = new LayuiTablePagingResult();
                result.setCode(RetCode.SUCCESS.getCode());
                result.setMsg(RetCode.SUCCESS.getMsg());
                result.setCount(pageInfo.getTotal());
                result.setData(pageInfo.getList());
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("managerSearch" + e.getMessage());
            result.setCode(RetCode.REQUEST_ERROR);
            result.setData(e.getMessage());
        }
        return result;


    }


    //页面按照月供或总利息查询Asc
    @Override
    public LayuiTablePagingResult interestAndSupply(Integer page, Integer size, String totleFee, String monthlySupply) {
        LayuiTablePagingResult result = null;
        try {
            PageHelper.startPage(page, size);
            List<Map<String, Object>> bySupply = dcManagerProductMapper.selectBySupply(totleFee, monthlySupply);
            PageInfo<ManagerProduct> pageInfo = new PageInfo(bySupply);
            result = new LayuiTablePagingResult();
            result.setCode(RetCode.SUCCESS.getCode());
            result.setMsg(RetCode.SUCCESS.getMsg());
            result.setCount(pageInfo.getTotal());
            result.setData(pageInfo.getList());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("interestAndSupply" + e.getMessage());
        }
        return result;
    }

    @Override
    public Response getDetail(Integer id) {
        Response response = new Response();
        Map<String, Object> rest = dcManagerProductMapper.getDetail(id);
        response.setData(rest);
        response.setCode(RetCode.SUCCESS);
        return response;
    }

    @Override
    public Response changeStatus(Integer id, Integer publishStatus) {
        Response response = new Response();
        Integer rest = dcManagerProductMapper.changeStatus(id, publishStatus);
        if (rest > 0) {
            response.setCode(RetCode.SUCCESS);
        } else {
            response.setCode(RetCode.UPDATEERROR);
        }
        return response;
    }

    @Override
    public Response getOrder(String phone) {
        Response response = new Response();
        try {
            PayOrder payOrder = new PayOrder();
            payOrder.setMobile(phone);
            PayOrder res = payOrderMapper.selectOne(payOrder);
            response.setCode(RetCode.SUCCESS);
            response.setData(res);
        } catch (Exception e) {
            response.setCode(RetCode.REQUEST_ERROR);
            response.setData(e.getMessage());
        }
        return response;
    }
}
